<?php
require_once('../src/functions.php');
require_once('../src/type_transaction.class.php');
require_once('../src/type_bien.class.php');
require_once('../src/localisation.class.php');

$data = array();
if (isset($_SESSION['search_annonces']) && !empty($_SESSION['search_annonces']))
    $data = $_SESSION['search_annonces'];
if (isset($_POST) && !empty($_POST))
    $data = $_POST;

// suppression du donnees du formulaire
if ( isset($_GET['erase']) && $_GET['erase']=='search' ) {
	$data = '';
	$_SESSION['search_annonces'] = '';
	//header('Location: /rechercher'); exit();
}
?>

<form id="search_form" method="post" action="/rechercher">
<fieldset>
	<legend>rechercher</legend>
	<p>
<?php
$type_bien_id = false;
if (isset($data['type_bien_id']))
    $type_bien_id = $data['type_bien_id'];
$type_bien = new type_bien();
echo $type_bien->getSelect($type_bien_id);
?>
	</p>
	<p>
<?php
$type_transaction_id = false;
if (isset($data['type_transaction_id']))
    $type_transaction_id = $data['type_transaction_id'];
$type_transaction = new type_transaction();
echo $type_transaction->getSelect($type_transaction_id);
?>
	</p>
	<p>
<?php
$localisation_id = false;
if (isset($data['localisation_id']))
    $localisation_id = $data['localisation_id'];
$localisation = new localisation();
echo $localisation->getSelect($localisation_id);
?>
	</p>
	<p>
		<span>Prix</span> entre
		<input type="text" size="8" id="prix_mini" name="prix_mini" value="<?php if (isset($data['prix_mini'])) echo $data['prix_mini']; ?>" />
		et
		<input type="text" size="8" id="prix_maxi" name="prix_maxi" value="<?php if (isset($data['prix_maxi'])) echo $data['prix_maxi']; ?>" />
	</p>
	<p id="currencyForm">
		<label for="currencyEUR">
			en euros&nbsp;
			<?php echo getFlag('eu', "drapeau de l'europe") ?>
		</label>
		<input type="radio" id="currencyEUR" name="currency" value="EUR" />		
		<label for="currencyDZD">
			en dinars&nbsp;
			<?php echo getFlag('dz', "drapeau de l'algerie") ?>
		</label>
		<input type="radio" id="currencyDZD" name="currency" value="DZD" />		
	</p>
	<p>
		<span>Surface</span> entre
		<input type="text" size="6" id="surface_mini" name="surface_mini" value="<?php if (isset($data['surface_mini'])) echo $data['surface_mini']; ?>" />
		et
		<input type="text" size="6" id="surface_maxi" name="surface_maxi" value="<?php if (isset($data['surface_maxi'])) echo $data['surface_maxi']; ?>" />
	</p>
	<p>
		<span>Pièce</span> entre
		<input type="text" size="4" id="piece_mini" name="piece_mini" value="<?php if (isset($data['piece_mini'])) echo $data['piece_mini']; ?>" />
		et
		<input type="text" size="4" id="piece_maxi" name="piece_maxi" value="<?php if (isset($data['piece_maxi'])) echo $data['piece_maxi']; ?>" />
	</p>
	<p class="submit">
<?php
// affichage d'un lien de remise a zero
// que dans le cas ou il y a deja une recherche effectuee
if( isset($data) && !empty($data) ) {
	empty($_GET) ? $marker = '?' : $marker = '&';
	echo '<a href="' . $_SERVER['REQUEST_URI'] . $marker . 'erase=search" class="reset">RAZ</a>';
}
?>
		<input type="submit" id="submit" name="submit" class="submit" value="Rechercher" />
	</p>
</fieldset>
</form>
<p id="block-link">Accéder à la <a href="/annonces?all">liste complète</a>.</p>
